<fieldset>
	<legend> Categories </legend>
		<br/>
			<div id="champs">
				<?php
					if (isset($message)) {
						echo "<h3>";
						echo $message;
						echo "</h3>";
					} else {
						echo "<TABLE BORDER=","1",">
							<CAPTION> Liste des categories : </CAPTION>
							<TR>
								<TH> Index </TH>
								<TH> Nom </TH>
								<TH> Commentaire </TH>";
							if (isset($_SESSION['droit']) && $_SESSION['droit'] == 1)
								echo "<TH> Nombre forum </TH>";
							if (isset($_SESSION['droit']) && $_SESSION['droit'] == 1)
								echo "<TH> Action </TH>
							</TR>";
				
						$max = count($tab['id_categ']);
						for($i=0 ; $i < $max ; $i++) {
							echo "<TR>";
							echo "<TD>", $tab['id_categ'][$i], "</TD>";
							echo "<TD>", $tab['name_categ'][$i], "</TD>";
							echo "<TD>", $tab['comment_categ'][$i], "</TD>";
							if (isset($_SESSION['droit'])) {
								$id = $tab['id_categ'][$i];
								require_once("model/forumBD.php");
								$nb_forum=select_nb_forum_categ($id);
								if($_SESSION['droit'] == 1)
									echo "<TD>", $nb_forum['nb_forum'], "</TD>";
									if($_SESSION['droit'] == 1) {
										echo "<TD>";
										echo "<a href=\"index.php?page=view_category&id_categ=$id\" onClick=\"affiche_cache('update_categ')\">";
										echo "<img src=\"./images/action/feuille.png\" title=\"Modifier la categorie\"/>";
										echo "</a>";
										echo "<a href=\"index.php?page=delete_category&id_categ=$id\">";
										echo "<img src=\"./images/action/croix.png\"/ title=\"Supprimer la categorie\">";
										echo "</a>";
										echo "</TD>";
									}
							}
							echo "</TR>";
						} 
						echo "</TABLE>";
					}
				?>
				<?php
					if (isset($_SESSION['droit']))
						if($_SESSION['droit'] == 1) {
							echo "<div id=","add_comments",">
								<p><input type=","submit"," name=","bt_add_comment"," value=\"Ajouter une categorie\" /> </p>
								</div>";
						}
				?>
				<div class="add_comment">
					</br>
					</br>
					<form method="post" action="index.php?page=add_category" onSubmit="return verifFormCateg(this)">
						<fieldset>
							<div id="champs_categ">
								<label for="name_categ"> Nom : </label>
								<input name="name_categ"/><br/>
								<label for="comment_categ"> Commentaire : </label>
								<input name="comment_categ"/><br/>
							</div> <!-- fin div champs_categ -->
						</fieldset>
						<p style="text-align:right"><input type="submit" value="Envoyer"/></p>
					</form>
				</div> <!-- fin div add_comment -->
				
				<div id="update_categ" style="display: <?php if (isset($display)) echo $display; else echo "none"; ?> ">
					</br>
					</br>
					<form method="post" action="index.php?page=update_category" onSubmit="return verifFormCateg(this)">
						<fieldset>
							<div id="champs_categ">
								<input name="id_categ" value="<?php echo $tab['id_categ'][0]; ?>" style="display: none"/>
								<label for="name_categ"> Nom : </label>
								<input name="name_categ" value="<?php echo $tab['name_categ'][0]; ?>"/><br/>
								<label for="comment_categ"> Commentaire : </label>
								<input name="comment_categ" value="<?php echo $tab['comment_categ'][0]; ?> "/><br/>
							</div> <!-- fin div champs_categ -->
						</fieldset>
						<p style="text-align:right"><input type="submit" value="Envoyer"/></p>
					</form>
				</div> <!-- fin div update_categ --> 
			</div> <!-- fin div champs -->
</fieldset>

<?php
	if (isset($_GET['numpage'])) {
		echo "<ul id=\"choix\">";
			if ($_GET['numpage'] == 1 || ($_GET['numpage'] > $tab['nombreDePages'] && $tab['nombreDePages'] == 1))
				echo "<li class=\"page disabled\"> &lsaquo; Pre </li>";
			else {
				$nb = $_GET['numpage'] - 1;
				echo  "<li class=\"page\"><a href=\"index.php?page=category&numpage=$nb\"> &lsaquo; Pre </a></li>";
			}
			for ($i=1 ; $i <= $tab['nombreDePages'] ; $i++) {
				if ($_GET['numpage'] == $i || $_GET['numpage'] > $tab['nombreDePages'])
					echo "<li class=\"num_page\" id=\"current_page\">
							<a href=\"index.php?page=category&numpage=$i\"> $i </a>
						  </li>";
				else
					echo "<li class=\"num_page\">
						<a href=\"index.php?page=category&numpage=$i\"> $i </a>
					  </li>";
			}
			if ($_GET['numpage'] >= $tab['nombreDePages'])
				echo "<li class=\"page disabled\"> Suiv &rsaquo; </li>";
			else {
				$nb = $_GET['numpage'] + 1;
				echo  "<li class=\"page\"><a href=\"index.php?page=category&numpage=$nb\"> Suiv &rsaquo; </a></li>";
			}
        echo "</ul>";
	}
?>
